<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>添加场地布置</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" th:href="@{/plugins/layui/css/layui.css}" media="all" />
	<link rel="stylesheet" th:href="@{/plugins/font-awesome/css/font-awesome.min.css}">
</head>

<body>
	<div style="margin: 15px;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			<legend>添加场地布置商品</legend>
		</fieldset>
		<form class="layui-form" enctype="multipart/form-data" class="layui-form">
			<div class="layui-form-item">
				<label class="layui-form-label">标题</label>
				<div class="layui-input-block">
					<input type="text" value="" name="title" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">价格</label>
				<div class="layui-input-block">
					<input type="text" name="price" value="" lay-verify="required|price" autocomplete="off" placeholder="请输入价格" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">数量</label>
				<div class="layui-input-block">
					<input type="text" value="" name="num" lay-verify="number" autocomplete="off" placeholder="请输入场地数量" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">所属分类</label>
				<div class="layui-input-inline">
					<select name="category" lay-verify="required">
							<option value="">请选择分类</option>

						</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">描述</label>
				<div class="layui-input-block">
					<input type="text" value="" name="description" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" type="submit" lay-submit="" lay-filter="add">立即提交</button>
				</div>
			</div>
		</form>
	</div>
	<script type="text/html" id="typeTpl">
		<% for(var i=0;i<$data.length;i++){ %>
		 <option value="<%==$data[i].dcid%>"><%==$data[i].catName%></option>
		 <%}%>
	</script>
	<script type="text/javascript" src="/admin/plugins/layui/layui.js"></script>
	<script type="text/javascript" src="/admin/js/public.js"></script>
	<script type="text/javascript" src="../../js/template.js"></script>
	<script type="text/javascript" src="../../js/jquery.min.js"></script>
	<script>
		var id = getUrlParam("id");
		$.ajax({
			url: "/admin/dec/cat/list/1?pageSize=100",
			datatype: "json",
			success: function(data) {
				var html = template('typeTpl', data.result.list);
				var element = document.querySelector("select[name='category']");
				element.innerHTML +=  html;
			}
		});
		layui.use(['form', 'layedit', 'laydate', 'element'], function() {
			var form = layui.form(),
				layer = layui.layer,
				layedit = layui.layedit,
				laydate = layui.laydate;
			var $ = layui.jquery,
				element = layui.element();

			//自定义验证规则

			form.verify({
				price: function(value, item) {
					if (isNaN(value)) {
						return "价格格式不正确";
					}
				}
			});


			form.on('submit(add)', function(data) {
				console.log(data);


				var url = "/admin/dec/pro/add?title="+data.field.title+"&description="+data.field.description+"&number="+data.field.num+"&price="+data.field.price+"&decoration.did="+id+"&productCatrgory.dcid="+data.field.category;

				$.ajax({
					url: url,
					type: "post",
					datatype: "json",
					success: function(data) {
						if (data.code == 200) {
							layer.open({
								content: '添加成功去上传图片后就可以在前台显示',
								btn: ['去上传图片', '取消'],
								yes: function(index, layero) {
									//按钮【按钮一】的回调
									location.href = "/admin/img?type=布置&id="+data.result;
								}
							});
						}
					}
				});
				return false;
			});
		});
	</script>
</body>

</html>
